"""
字典值{'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}意味着玩
家有 1 条绳索、6 个火把、42 枚金币等。
写一个名为 displayInventory()的函数，它接受任何可能的物品清单，并显示如下：
Inventory:
12 arrow
42 gold coin
1 rope
6 torch
1 dagger
Total number of items: 62
"""


def displayInventory(inventory):
    print("inventory:")
    count = 0
    for k, v in inventory.items():
        print(str(v) + " " + str(k))
        count += v
    print("Total count :" + str(count))


"""
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
写一个名为 addToInventory(inventory, addedItems)的函数，其中 inventory 参数
是一个字典，表示玩家的物品清单，addedItems 参数是一个列表，就像 dragonLoot
"""


def addToInventory(inventory, addedItems):
    for item in addedItems:
        inventory[item] = inventory.get(item, 0)+1
    return inventory


if __name__ == "__main__":
    inv = {'gold coin': 42, 'rope': 1}
    dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
    inv = addToInventory(inv, dragonLoot)
    displayInventory(inv)
